package com.xwaf.platform.system.auth;

import java.io.IOException;
import java.util.TimeZone;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * <p>
 * Auth <br>
 * Spring-boot 启动入口
 * <p>
 * 
 * @author 李聪 <br>
 * @email xwaf_love@yeah.net <br>
 * @since JDK 1.8<br>
 * @date 2019年12月27日 下午7:57:15 <br>
 * @see 无<br>
 *      Copyright (c) 2019, xwaf_love@yeah.net All Rights Reserved.<br>
 */
@RestController
@ServletComponentScan
@ComponentScan(basePackages = { "com.xwaf" })
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class })
@EnableTransactionManagement // 启用事务
@ImportResource("classpath:dubbo-provider.xml")
@EnableScheduling
@EnableAsync // 启用异步
public class AuthApplication {

	private static final Logger LOGGER = LoggerFactory.getLogger(AuthApplication.class);

	@RequestMapping
	public String hello() {
		return "Hello World!";
	}

	// 健康检查
	@RequestMapping("/check")
	public String check() {
		return "success";
	}

	@PostConstruct
	void started() {
		TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
	}

	/**
	 * 
	 * <p>
	 * The entry point of application.
	 * <p>
	 * 
	 * @author 李聪 <br>
	 * @email xwaf_love@yeah.net <br>
	 * @since JDK 1.8<br>
	 * @date 2019年12月30日 上午9:11:36 <br>
	 * @see 无<br>
	 * @param args
	 *            the input arguments
	 * @throws IOException
	 *             the io exception
	 * @demo <br>
	 */
	public static void main(String[] args) throws IOException {
		SpringApplication application = new SpringApplication(AuthApplication.class);
		application.setRegisterShutdownHook(false);
		application.setBannerMode(Banner.Mode.OFF);
		ConfigurableApplicationContext context = application.run(args);
		// 可以 验证我们的bean是否成功注入
		// context.getBean("auth");
		// application.run(args);
		Assert.notNull(true, "main started");// 可用於錯誤处理
		LOGGER.info("platform-system-auth started!!!");
	}
}
